;(function () {
  // 在编教师同一单位工作年限情况（人数）
  var durationChart = null
  function durationChartInit(res) {
    var durationChartId = document.getElementById('durationChart')
    if (!durationChartId) return
    durationChart = echarts.init(durationChartId)
    var head = []
    // 2025-01-13 start
    var ggList = []
    var fggList = []
    for (var i = 0; i < res.length; i++) {
      var item = res[i]
      head.push(item[0])
      ggList.push(item[3]) // 骨干
      fggList.push(item[4]) // 非骨干
    }
    var option = {
      tooltip: {
        trigger: 'item',
        backgroundColor: 'rgba(4, 31, 53, 0.9)',
        borderWidth: 0,
        textStyle: {
          color: '#fff',
          fontSize: '14px',
        },
        formatter: function (params) {
          var item = res[params.dataIndex]
          return (
            '<div style="color:#FFFFFF;"><p style="font-size:14px">' +
            params.name +
            '</p><p style="font-size:10px;padding:5px 0 2px 0;">总人数：<span style="font-size:12px;color:#19E1FF">' +
            item[1] +
            '人</span></p><p style="font-size:10px;padding:2px 0 5px 0;border-bottom:1px solid #206195">总占比：<span style="font-size:12px;color:#F88E30">' +
            item[2] +
            '%</span></p><p style="color:#FCA12B;font-size:10px;padding:5px 0 2px 0;">骨干人数：<span style="font-size:12px;color:#fff">' +
            item[3] +
            '人</span></p><p style="color:#2BBAFC;font-size:10px;padding:2px 0;">非骨干：<span style="font-size:12px;color:#fff">' +
            item[4] +
            '人</span></p></div>'
          )
        },
      },
      grid: {
        top: '12%',
        left: '0',
        right: '0',
        bottom: '5%',
        containLabel: true,
      },
      xAxis: {
        type: 'category',
        data: head,
        axisLine: {
          lineStyle: {
            color: '#7FDDFC',
          },
        },
        axisLabel: {
          textStyle: {
            color: '#fff',
          },
          formatter: function (value) {
            return value.length > 6
              ? value.slice(0, 6) + '\n' + value.slice(6)
              : value
          },
        },
      },
      yAxis: {
        type: 'value',
        splitLine: {
          lineStyle: {
            color: 'rgba(89, 143, 205, 0.2)',
          },
        },
        axisLabel: {
          textStyle: {
            color: '#fff',
          },
        },
        axisLine: {
          show: true,
          lineStyle: {
            color: '#7FDDFC',
          },
        },
      },
      series: [
        {
          data: fggList,
          type: 'bar',
          barWidth: '30%',
          itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: 'rgba(43, 186, 252, 0.7)' },
              { offset: 1, color: 'rgba(43, 186, 252, 0.1)' },
            ]),
          },
          emphasis: {
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: 'rgba(43, 186, 252, 0.7)' },
                { offset: 1, color: 'rgba(43, 186, 252, 0.7)' },
              ]),
            },
          },
        },
        {
          data: ggList,
          type: 'bar',
          barWidth: '30%',
          itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: 'rgba(252, 161, 43, 0.7)' },
              { offset: 1, color: 'rgba(252, 161, 43, 0.1)' },
            ]),
          },
          emphasis: {
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: 'rgba(252, 161, 43, 0.7)' },
                { offset: 1, color: 'rgba(252, 161, 43, 0.7)' },
              ]),
            },
          },
        },
      ],
    }
    // 2025-01-13 end
    durationChart.setOption(option)
  }

  // 在编教师同单一单位工作年限情况
  var schoolWorkYearChart = null
  function schoolWorkYearChartInit(res) {
    var schoolWorkYearChartId = document.getElementById('schoolWorkYearChart')
    if (!schoolWorkYearChartId) return
    schoolWorkYearChart = echarts.init(schoolWorkYearChartId)
    var head = []
    var zbList = []
    var ggList = []
    for (var i = 0; i < res.length; i++) {
      var item = res[i]
      head.push(item[0])
      zbList.push(item[1]) // 在编
      ggList.push(item[3]) // 骨干
    }
    var option = {
      tooltip: {
        trigger: 'item',
        backgroundColor: 'rgba(4, 31, 53, 0.9)',
        borderWidth: 0,
        textStyle: {
          color: '#fff',
          fontSize: '14px',
        },
        formatter: function (params) {
          // console.log(params)
          var item = res[params.dataIndex]
          return (
            '<div style="color:#FFFFFF;"><p style="font-size:14px">' +
            params.name +
            '</p><p style="font-size:10px;padding:5px 0 2px 0;">总人数：<span style="font-size:12px;color:#19E1FF">' +
            item[1] +
            '人</span></p><p style="font-size:10px;padding:2px 0 5px 0;border-bottom:1px solid #206195">总占比：<span style="font-size:12px;color:#F88E30">' +
            item[2] +
            '%</span></p><p style="color:#FCA12B;font-size:10px;padding:5px 0 2px 0;">在编教师：<span style="font-size:12px;color:#fff">' +
            item[1] +
            '人</span></p><p style="color:#2BBAFC;font-size:10px;padding:2px 0;">骨干教师：<span style="font-size:12px;color:#fff">' +
            item[3] +
            '人</span></p></div>'
          )
        },
      },
      grid: {
        top: '12%',
        left: '0',
        right: '2%',
        bottom: '5%',
        containLabel: true,
      },
      xAxis: {
        type: 'category',
        data: head,
        axisLine: {
          lineStyle: {
            color: '#7FDDFC',
          },
        },
        axisLabel: {
          interval: 0,
          textStyle: {
            color: '#fff',
          },
          formatter: function (value) {
            return value.length > 3
              ? value.slice(0, 3) + '\n' + value.slice(3)
              : value
          },
        },
      },
      yAxis: {
        type: 'value',
        splitLine: {
          lineStyle: {
            color: 'rgba(89, 143, 205, 0.2)',
          },
        },
        axisLabel: {
          textStyle: {
            color: '#fff',
          },
        },
        axisLine: {
          show: true,
          lineStyle: {
            color: '#7FDDFC',
          },
        },
      },
      series: [
        {
          data: ggList,
          type: 'bar',
          barWidth: '40%',
          stack: '工作年限',
          itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: 'rgba(252, 161, 43, 0.8)' },
              { offset: 1, color: 'rgba(252, 161, 43, 0.1)' },
            ]),
          },
          emphasis: {
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: 'rgba(252, 161, 43, 0.8)' },
                { offset: 1, color: 'rgba(252, 161, 43, 0.8)' },
              ]),
            },
          },
        },
        {
          data: zbList,
          type: 'bar',
          barWidth: '40%',
          stack: '工作年限',
          itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: 'rgba(43, 186, 252, 0.8)' },
              { offset: 1, color: 'rgba(43, 186, 252, 0.2)' },
            ]),
          },
          emphasis: {
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: 'rgba(43, 186, 252, 0.8)' },
                { offset: 1, color: 'rgba(43, 186, 252, 0.8)' },
              ]),
            },
          },
        },
      ],
    }
    schoolWorkYearChart.setOption(option)
  }

  // 在编骨干情况
  function teacherCoreChartInit(data) {
    var teacherCoreChartId = document.getElementById('teacherCoreChart')
    if (!teacherCoreChartId) return
    var teacherCoreChart = echarts.init(teacherCoreChartId)
    var header = []
    var list = []
    var total = data[0][1]
    for (var i = 1; i < data.length; i++) {
      var item = data[i]
      header.push(item[0])
      list.push({
        name: item[0],
        value: +item[1],
      })
    }
    var result = {
      legend: {
        data: header,
      },
      series: {
        type: 'pie',
        name: ['数量'],
        data: list,
      },
    }
    var styleList = ['#1890FF', '#1EE7E7', '#01BB09', '#EC591F', '#FFAC26']
    try {
      var dataList = result.series.data
      var length = dataList.length
      for (var i = 0; i < length; i++) {
        dataList[i].value = +dataList[i].value
        dataList[i].itemStyle = {
          color: styleList[i],
        }
      }
    } catch (error) {
      console.log(error)
    }
    var option = {
      tooltip: {
        trigger: 'item',
        backgroundColor: 'rgba(44, 78, 155, 0.8)',
        borderWidth: 0,
        textStyle: {
          color: '#fff',
          fontSize: '0.4rem',
        },
      },
      legend: {
        //  2025-01-08 start
        x: '54%',
        //  2025-01-08 end
        y: 'middle',
        // icon: 'circle',
        itemWidth: 8,
        itemHeight: 8,
        orient: 'vertical',
        formatter(name) {
          var info = {}
          for (var i = 0; i < list.length; i++) {
            list[i].name === name && (info = list[i])
          }
          return '{a|' + info.name + '} ' + '   {b|' + info.value + '} {c|人}'
        },
        textStyle: {
          rich: {
            a: {
              fontSize: 12,
              color: '#C0DEEF',
            },
            b: {
              fontSize: 14,
              color: '#19E1FF',
            },
            c: {
              fontSize: 12,
              color: '#fff',
            },
          },
        },
      },
      series: [
        {
          name: '在编骨干情况',
          type: 'pie',
          radius: ['45%', '70%'],
          center: ['20%', '50%'],
          data: dataList,
          label: {
            show: false,
          },
          labelLine: {
            show: false,
          },
          label: {
            show: true,
            position: 'center',
            fontSize: 18,
            formatter: '{a|' + total + '}' + '\n{b|总人数}',
            rich: {
              a: {
                color: '#fff',
                fontSize: 22,
                fontWeight: 'bold',
                lineHeight: 34,
              },
              b: {
                color: '#A1B7C3',
                fontSize: 10,
              },
            },
          },
        },
        {
          name: '遮罩层',
          type: 'pie',
          radius: ['55%', '70%'],
          center: ['20%', '50%'], // 这个环形的半径会遮住内环部分
          itemStyle: {
            color: 'rgba(0, 0, 0, 0.6)', // 半透明白色遮罩
          },
          hoverAnimation: false, // 禁用遮罩的动画效果
          data: [{ value: 1 }], // 只添加一个占位数据
          silent: true,
          labelLine: {
            show: false,
          },
        },
      ],
    }
    teacherCoreChart.setOption(option)
  }

  // 在编骨干情况-学校详情
  function teacherSchoolCoreChartInit(data) {
    var teacherSchoolCoreChartId = document.getElementById(
      'teacherSchoolCoreChart'
    )
    if (!teacherSchoolCoreChartId) return
    var teacherSchoolCoreChart = echarts.init(teacherSchoolCoreChartId)
    var header = []
    var list = []
    var total = data[0][1]
    for (var i = 1; i < data.length; i++) {
      var item = data[i]
      header.push(item[0])
      list.push({
        name: item[0],
        value: +item[1],
      })
    }
    var result = {
      legend: {
        data: header,
      },
      series: {
        type: 'pie',
        name: ['数量'],
        data: list,
      },
    }
    console.log(result)
    var styleList = ['#1890FF', '#1EE7E7', '#01BB09', '#EC591F', '#FFAC26']
    try {
      var dataList = result.series.data
      var length = dataList.length
      for (var i = 0; i < length; i++) {
        dataList[i].value = +dataList[i].value
        dataList[i].itemStyle = {
          color: styleList[i],
        }
      }
    } catch (error) {
      console.log(error)
    }
    var option = {
      tooltip: {
        trigger: 'item',
        backgroundColor: 'rgba(44, 78, 155, 0.8)',
        borderWidth: 0,
        textStyle: {
          color: '#fff',
          fontSize: '0.4rem',
        },
      },
      legend: {
        //  2025-01-08 start
        x: '64%',
        //  2025-01-08 end
        y: 'middle',
        // icon: 'circle',
        itemWidth: 8,
        itemHeight: 8,
        orient: 'vertical',
        textStyle: {
          color: '#7CA1D2',
        },
        formatter(name) {
          var info = {}
          for (var i = 0; i < list.length; i++) {
            list[i].name === name && (info = list[i])
          }
          return '{a|' + info.name + '} ' + '   {b|' + info.value + '} {c|人}'
        },
        textStyle: {
          // 添加
          rich: {
            a: {
              fontSize: 12,
              color: '#C0DEEF',
            },
            b: {
              fontSize: 14,
              color: '#19E1FF',
            },
            c: {
              fontSize: 12,
              color: '#fff',
            },
          },
        },
      },
      series: [
        {
          name: '在编骨干情况',
          type: 'pie',
          //  2025-01-08 start
          radius: ['35%', '55%'],
          center: ['30%', '50%'],
          //  2025-01-08 end
          data: dataList,
          label: {
            show: false,
          },
          labelLine: {
            show: false,
          },
          label: {
            show: true,
            position: 'center',
            fontSize: 18,
            formatter: '{a|' + total + '}' + '\n{b|总人数}',
            rich: {
              a: {
                color: '#fff',
                fontSize: 22,
                fontWeight: 'bold',
                lineHeight: 34,
              },
              b: {
                color: '#A1B7C3',
                fontSize: 10,
              },
            },
          },
        },
        {
          name: '遮罩层',
          type: 'pie',
          //  2025-01-08 start
          radius: ['45%', '55%'],
          center: ['30%', '50%'], // 这个环形的半径会遮住内环部分
          //  2025-01-08 end
          itemStyle: {
            color: 'rgba(0, 0, 0, 0.6)', // 半透明白色遮罩
          },
          hoverAnimation: false, // 禁用遮罩的动画效果
          data: [{ value: 1 }], // 只添加一个占位数据
          silent: true,
          labelLine: {
            show: false,
          },
        },
      ],
    }
    teacherSchoolCoreChart.setOption(option)
  }

  window.durationChartInit = durationChartInit
  window.schoolWorkYearChartInit = schoolWorkYearChartInit
  window.teacherCoreChartInit = teacherCoreChartInit
  window.teacherSchoolCoreChartInit = teacherSchoolCoreChartInit

  $(window).resize(function () {})
})()
